<template>
	<view class="wrap">
		<view class="top">
			<u-icon name="order" class="logo"></u-icon>Kant Boot软件需求平台
		</view>
		<view class="content">

			<view class="title">欢迎注册Kant Boot</view>


<!-- 			<u-field class="u-border-bottom" v-model="user.username" icon="account-fill" placeholder="设置账号">
			</u-field> -->

			<view style="height: 30rpx;"></view>
			<u-field class="u-border-bottom" v-model="user.nickname" icon="play-right-fill" placeholder="设置昵称">
			</u-field>
			<view style="height: 30rpx;"></view>

			<view style="height: 30rpx;"></view>


			<u-field class="u-border-bottom" v-model="user.password" type="password" :icon="passwordIcon"
				@focus="passwordFocus()" @blur="passwordBlur()" placeholder="输入密码">
			</u-field>

			<view style="height: 30rpx;"></view>

			<u-field class="u-border-bottom" v-model="password2" type="password" :icon="passwordIcon"
				@focus="passwordFocus()" @blur="passwordBlur()" placeholder="再次输入密码">
			</u-field>

			<view style="height: 60rpx;"></view>

			<view style="width: 80%;margin-left: 50%;transform: translateX(-50%);border: 2rpx solid rgba(118,118,118,.3);border-radius: 20rpx;padding: 20rpx;">
				<u-divider>手机号</u-divider>
				<u-field class="u-border-bottom" v-model="user.phoneNumber" type="number" icon="phone-fill"
					placeholder="填写你的手机号码">
				</u-field>
				<view style="height: 50rpx;"></view>
				<u-divider>验证码</u-divider>
				<u-message-input></u-message-input>
			</view>
			
			<view class="tips" style="height: 40rpx;"></view>
			<u-button @click="join" :ripple="true" ripple-bg-color="#F0F0F0" type="warning" class="getCaptcha">注册
			</u-button>
			<u-button @click="toLogin()" size="mini" :ripple="true" style="position: fixed;bottom: 20rpx;right: 20rpx;" ripple-bg-color="#F0F0F0" type="primary">前往登录</u-button>
			
			
			<view class="alternative">
				<view class="password"></view>
			</view>
		</view>


		<u-toast ref="uToast" />
	</view>
	</view>
</template>

<script>
	import Request from '../../utils/Request.js'
	import Util from '../../utils/Util.js'
	
	let that;
	export default {
		data() {
			return {
				passwordIcon: "lock-fill",
				user: {
					nickname: null,
					password: null,
					phoneNumber: null,
				},
				password2: null
			}
		},
		mounted() {
			that = this;
		},
		computed: {},
		methods: {
			passwordFocus() {
				this.passwordIcon = "lock-opened-fill";
			},
			passwordBlur() {
				this.passwordIcon = "lock-fill";
			},
			toLogin(){
				uni.navigateTo({
					url:"../login/login"
				})
			},
			join() {
				var user = this.user;
				if(user.nickname == null){
					that.$refs.uToast.show({
						title: "昵称不能为空",
						type: 'warning',
						duration: '2300'
					});
					return;					
				}
				if(user.password==null){
					that.$refs.uToast.show({
						title: "密码不能为空",
						type: 'warning',
						duration: '2300'
					});
					return;
				}
				if(user.password.length<6){
					that.$refs.uToast.show({
						title: "密码长度不能小于6",
						type: 'warning',
						duration: '2300'
					});
					return;
				}
				if(this.password2==null){
					that.$refs.uToast.show({
						title: "请再次输入密码",
						type: 'warning',
						duration: '2300'
					});
					return;
				}
				if(user.phoneNumber==null){
					that.$refs.uToast.show({
						title: "手机号码不能为空",
						type: 'warning',
						duration: '2300'
					});
					return;
				}

				if(this.password2!=this.user.password){
						that.$refs.uToast.show({
							title: "两次密码不一致",
							type: 'warning',
							duration: '2300'
						});
						return;
				}
				Util.requestInNotLoginPage({
					url: Request.path + "ces-user/join",
					data: that.user,
					success(res) {
						if (res.data.state == 2000) {
							that.$refs.uToast.show({
								title: res.data.msg,
								type: 'success',
								duration: '2300'
							});
							uni.navigateTo({
								url: "../login/login"
							})
						}
						that.$refs.uToast.show({
							title: res.data.errMsg,
							type: 'error',
							duration: '2300'
						});
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.top {
		padding: 30rpx;
		color: $fyf-font-color;
		font-weight: bold;

		.logo {
			font-size: 35rpx;
			color: #FFFFFF;
			background: $fyf-button-background;
			padding: 10rpx;
			border-radius: 55%;
			margin-right: 10rpx;
		}
	}

	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;
			text-align: left;

			.title {
				text-align: left;
				font-size: 45rpx;
				font-weight: 500;
				margin-bottom: 0rpx;
			}

			.u-border-bottom {
				border-bottom: 1rpx solid gray;
			}

			input {
				text-align: left;

				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.issue {
				color: $fyf-font-color;
			}

			.getCaptcha {
				color: $fyf-button-color;
				border: none;
				width: 60%;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.getCaptcha::active {
				color: $fyf-button-color;
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}

		.buttom {
			position: relative;
			bottom: 0;

			.loginType {
				display: flex;
				padding: 100rpx 150rpx 150rpx 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-type-warning;
				}
			}
		}
	}
</style>
